package com.allwees.bs.c.module.app.controller;

import com.allwees.bs.c.module.ops.controller.AdsController;
import com.allwees.bs.c.module.ops.controller.MarketingController;
import com.allwees.bs.c.module.product.controller.ProductController;
import com.allwees.bs.c.module.product.service.CategoryService;
import com.allwees.bs.core.model.constant.CacheName;
import com.allwees.bs.core.modelbase.page.PageParams;
import com.allwees.bs.core.modelbase.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 把一些首页的小接口做一下聚合
 *
 * @author Daniel
 * @version 1.0.0
 * @since 2020/11/19 19:09
 */
@RestController
@RequestMapping("/api/home/mix")
public class AggreController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private MarketingController marketingController;

    @Autowired
    private AdsController adsController;

    @Autowired
    private ProductController productController;

    @Cacheable(cacheNames = CacheName.APP_AGGREGATE, key = "#platform", sync = true)
    @GetMapping
    public R aggregate(@RequestParam(name = "platform", defaultValue = "1") String platform) {
        Map<String, Object> result = new HashMap<>();
//        String userUuid = UserContext.getUserUuid();
//        if (StringUtils.isNotBlank(userUuid)) {
//            //https://api.allwees.com/api/v1/marketing/gift/info
//            result.put("got", marketingController.freeGiftGetInfo().get("data"));
//            //https://api.allwees.com/api/v1/user/me
//            result.put("me", userService.userInfo(userUuid));
//        }
        //https://api.allwees.com/api/v2/app/init
        //result.put("cates", categoryService.getAllCategories());
        //https://api.allwees.com/api/v1/marketing/flash?current=1&size=4
        PageParams pageParams = new PageParams(1, 4);
        result.put("flash", marketingController.flashSales(pageParams, null).get("data"));
        //https://api.allwees.com/api/v1/marketing/gifts?current=1&size=4
        result.put("gifts", marketingController.freeGifts(pageParams).get("data"));
        //https://api.allwees.com/api/v1/ads/1/1
        result.put("ads", adsController.ads(1).get("data"));
        result.put("P01", productController.productsByCategory("P01", new PageParams(1, 12)));
        return R.ok(result);
    }
}
